<template>
  <div class="app">
    <h1>我是App组件</h1>
    <Child ref="haizi"/>
  </div>
</template>

<script>
  import Child from './components/Child'

  export default {
    name:'App',
    components:{Child},
    data() {
      return {
        x:100
      }
    },
    methods: {
      getToy(value){
        alert(`我是App，我儿子孝顺给了我一个玩具：${value}`)
      }
    },
    mounted() {
      this.$refs.haizi.$on('send-toy',this.getToy)

      // console.log(this) //App的vc
      // console.log(this.$refs.haizi)//Child的vc
    },
  }
</script>

<style>
  .app {
    background-color: skyblue;
    padding: 20px;
    box-shadow: 0 0 10px black;
    border-radius: 10px;
  }
</style>